<template>
	<scroll-view scroll-y class=""
		:style="{background:'url('+Imgbase+'/brave_goodindex_bgc.png)','background-size':'100%',}">
		<cu-custom bgColor="" :isBack="true">
			<block slot="content"></block>
		</cu-custom>
		<view class="padding-sm">
			<view class="margin-left">
				<view class="cu-avatar round fl"
					style="border: 3px solid #ffffff;width: 130upx;height: 130upx;margin-top: 0upx;margin-left: 30upx;"
					:style="[{ backgroundImage:'url(' + avatar + ')' }]" @click="copyUsername()"></view>
				<view class="padding-left fl" style="margin-top: 0upx;width: 70%;position: relative;">
					<view class="cu-progress round sm striped active fl"
						style="width: 50%;margin-left: 1%;margin-top: 8%;position: relative;">
						<view class="bg-progress" style="color: #333333;background-color: #c92b28;padding-top: 2rpx;"
							:style="[{ width:loading?levelpoint:''}]">
						</view>
						<text style="position: absolute;left: 25%;top: 0%;">{{levelnow}}/{{levelall}}</text>
					</view>
					<!-- 等级图标 -->
					<view class="fl" v-if="level.name == 'vipmax' || level.name == 'VIPMAX'">
						<image class="" style="width: 80upx;margin-left: 30upx;" mode="widthFix"
							:src="Imgbase + '/1zhan_levels_101.png'" @click="toPage('index','level')">
						</image>
					</view>
					<view class="" v-else>
						<view class="fl" v-for="(item,index) in 102" :key="index">
							<image class="" style="width: 80upx;margin-left: 30upx;" mode="widthFix"
								:src="Imgbase + '/1zhan_levels_' + index + '.png'" v-if="level.level == index"
								@click="toPage('index','level')">
							</image>
						</view>
					</view>
					
					<view style="clear: both;"></view>
					<view class="text-xxl text-bold" style="color: #8d2d24;margin-top: 0rpx;margin-left: 10upx;position: absolute;top: 60rpx;">
						{{nickname}}
					</view>
				</view>
			</view>
		</view>
		<view style="clear: both;"></view>
		<view style="width: 100%;height: 20upx;"></view>
		<view
			style="width: 94%;margin-left: 3%;background-color: white;border-radius: 30rpx 30rpx 0rpx 0rpx;min-height: 1500upx;">
			<block v-for="(item,index) in list">
				<view
					style="width: 90%;margin-left: 5%;height: 130upx;border-bottom: 1px solid #f6f6f6;position: relative;">
					<view style="color: #8d2d24;float: left;
					line-height: 120upx;text-align: center;width: 100upx;font-size: 32rpx;padding-top: 10upx;font-weight: bold;">
						{{item.name}}
					</view>
					<view v-if="item.state == 1"
						style="float: left;height: 130upx;width: 100upx;display: flex;justify-content: center;align-items: center;">
						<image src="/static/level/present.png" style="width: 60upx;height: 60upx;"></image>
					</view>
					<view v-if="item.state == 1"
						style="color: black;float: left;line-height: 120upx;font-size: 26rpx;padding-top: 10upx;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;width: 47%;">
						{{item.goodmes.name}}
					</view>
					<text class="cuIcon-check text-red"
						style="font-size: 50rpx;float: right;line-height: 130upx;padding-top: 0upx;margin-right: 20upx;"
						v-if="item.state == 1&&item.getnum != 0&&item.name != 'VIPMAX'"></text>
					<view style="color: black;float: right;line-height: 120upx;font-size: 26rpx;padding-top: 10upx;"
						v-if="item.state == 1&&item.getnum != 0&&item.name == 'VIPMAX'">已领取{{item.getnum}}次</view>
					<!--<view style="position: absolute;left: 2%;top: 70%;font-size: 26rpx;" >{{item.startpoint}}~{{item.endpoint}}</view>-->
				</view>
			</block>
		</view>
		<view style="clear: both;"></view>
	</scroll-view>
</template>

<script>
	export default {
		data() {
			return {
				Imgbase: getApp().globalData.Imgbase,
				id: null,
				nickname: '',
				avatar: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big21002.jpg',
				score: 0,
				money: 0,
				username: '',
				levelpoint: '60%',
				levelnow: 0,
				levelall: 0,
				level: 0,
				loading: false,
				list: [],
			}
		},
		methods: {
			getuser() {
				let _this = this;
				uni.request({
					url: _this.$globals.apibase + '/api/Userways/userFront',
					data: {
						token: uni.getStorageSync('token'),
					},
					method: 'POST',
					header: {
						'content-type': 'application/json'
					},
					success: (res) => {
						if (res.data.code == '401') {
							uni.setStorageSync('token', '');
							_this.$uniApi.trylogin();
						}
						if (res.data.code == '1') {
							_this.nickname = res.data.data.user_desc.nickname;
							_this.avatar = res.data.data.user_desc.avatar;
							_this.money = res.data.data.user_desc.money;
							_this.score = res.data.data.user_desc.score;
							_this.username = res.data.data.user_desc.username;
							_this.id = res.data.data.user_desc.id;
							_this.levelall = res.data.data.level_mes.endpoint;
							_this.levelnow = res.data.data.user_desc.empirical;
							_this.levelpoint = _this.levelnow / _this.levelall * 100 + '%';
							_this.level = res.data.data.level_mes;
						}
					}
				});
			},
			getlevel() {
				let _this = this;
				uni.request({
					url: _this.$globals.apibase + '/api/Userways/userLevel',
					data: {
						token: uni.getStorageSync('token'),
					},
					method: 'POST',
					header: {
						'content-type': 'application/json'
					},
					success: (res) => {
						if (res.data.code == '401') {
							uni.setStorageSync('token', '');
							_this.$uniApi.trylogin();
						}
						if (res.data.code == '1') {
							_this.list = res.data.data.list;
							for (var i = 0; i < _this.list.length; i++) {
								_this.list[i]['getnum'] = 0;
								for (var j = 0; j < res.data.data.userlist.length; j++) {
									if (res.data.data.userlist[j].level == _this.list[i]['level']) {
										_this.list[i]['getnum'] = res.data.data.userlist[j]['num'];
										break;
									}
								}
							}
						}
					}
				});
			},
		},
		onLoad(options) {
			this.getuser();
			let that = this;
			setTimeout(function() {
				that.loading = true
			}, 500)
			this.getlevel()
		}
	}
</script>

<style>
</style>
